// Always also include CF_bodyjs.js, so that functions like validateData will work.

function CF_ajtable(){

	this.syncVal = function(dbVariable,dbKey,elementID){
		var valElement = document.getElementById(elementID)
		if(valElement.type == 'checkbox'){
			if(valElement.checked){
				var newvalue = '1';
			}
			else{
				var newvalue = '0';
			}
		}
		else{
			var newvalue = valElement.value;
		}

		var oldValElID = 'OV_' + elementID;
		var oldvalue = document.getElementById(oldValElID).value;		
		
		
		
	
	//alert("dbVariable = " + dbVariable + " dbKey = " + dbKey + " elementID = " + elementID + " actionurl is " + 		this.url_syncval + " newvalue is " + newvalue + " oldvalue is " + oldvalue );
	if(oldvalue != newvalue){	
		$.getJSON(this.url_syncval,{sel: this.tablename, mode: "update", ks: this.keyvariables, kv: dbKey, field: dbVariable, value: newvalue},   function(data){
	     if(data.status == "OK"){
	     		//editCommand.execute();
	     }else{
	     		alert("Data Sync Error: " + data.msg);
	     		document.getElementById(oldValElID).value = oldvalue;
	     }
	   })
	} // end if oldvalue != newvalue
	
	}
	
} // end CF_ajtable
